package com.lanluo.service.concurrent.semaphore;

/**
 * 线程任务
 * @author
 * @date 2018-09-03-11:19
 */
public class ResourceUse implements Runnable{
    private ResourceManager manager;
    private int userid;

    public ResourceUse(ResourceManager manager, int userid) {
        this.manager = manager;
        this.userid = userid;
    }

    public void run() {
        System.out.println("准备使用资源");
        manager.userResource(userid);
    }

    /**
     * 10个线程访问5个资源
     * @param args
     */
    public static void main(String[] args) {
        ResourceManager manager = new ResourceManager();
        Thread[] threads = new Thread[10];
        for (int i = 0; i < 10; i++) {
            ResourceUse user = new ResourceUse(manager, i);
            threads[i] = new Thread(user);
            threads[i].start();
        }
    }
}